using System;
using System.ComponentModel;
using System.Collections.Generic;

namespace shfa.snomtastic.data.business
{
	[DataObject(true)]
    public partial class ModelController
    {
	
		public SqlDataProvider DataProvider { get; set; }

        public ModelController()
        {
            DataProvider = new SqlDataProvider();
        }
	
		[DataObjectMethod(DataObjectMethodType.Insert, true)]
        public Guid InsertModel(ModelInfo oi)
		{
            return DataProvider.InsertModel(oi.Name, oi.ErrorMessage, oi.ConfigurationId);
		}

		[DataObjectMethod(DataObjectMethodType.Update, true)]
        public int UpdateModel(ModelInfo oi) 
		{
			return DataProvider.UpdateModel(oi.ModelId, oi.Name, oi.ErrorMessage, oi.ConfigurationId);
		}
		
		[DataObjectMethod(DataObjectMethodType.Delete, true)]
        public int DeleteModel(Guid modelId)
		{
			return DataProvider.DeleteModel(modelId);
        }

		[DataObjectMethod(DataObjectMethodType.Select, true)]
        public ModelInfo SelectModel(Guid modelId)
        {    
			return ObjectFromDataRow(DataProvider.SelectModel(modelId));
        }
		
		[DataObjectMethod(DataObjectMethodType.Select, true)]
        public List<ModelInfo> SelectModels()
		{
            return ListFromDataTable(DataProvider.SelectModels());
        }
		
		[DataObjectMethod(DataObjectMethodType.Select, true)]
        public List<ModelInfo> SelectModels(string sortExpression)
        {
            List<ModelInfo> retList = SelectModels();
            if (sortExpression.Length > 0)
            {
                retList.Sort(new ModelComparer(sortExpression));
            }
            return retList;
        }

        [DataObjectMethod(DataObjectMethodType.Select, true)]
		public List<ModelInfo> SelectModelsByConfiguration(Guid configurationId)
		{
			return ListFromDataTable(DataProvider.SelectModelsByConfiguration(configurationId));
		}
		
        public List<ModelInfo> SelectModelsByConfiguration(Guid configurationId,string sortExpression)
		{
			List<ModelInfo> retList = SelectModelsByConfiguration(configurationId);
            if (sortExpression.Length > 0)
            {
                retList.Sort(new ModelComparer(sortExpression));
            }
            return retList;
		}

	}

}
		